package jk.zmn.socket.tcp.demo3;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * @author 张梦楠
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2018/5/3119:13
 * @blog www.itzmn.com
 */
public class Recive implements Runnable {

    //得到数据
    private DataInputStream dataInputStream = null;
    private boolean isRunning = true;

    public Recive(Socket socket){
        try {
            dataInputStream = new DataInputStream(socket.getInputStream());
        } catch (IOException e) {
            isRunning =false;
            CloseUtils.CloseAll(dataInputStream);
        }
    }

    public String recive(){
        String msg ="";
        try {
            msg = dataInputStream.readUTF();

        } catch (IOException e) {
            isRunning =false;
            CloseUtils.CloseAll(dataInputStream);
        }
        return msg;
    }
    @Override
    public void run() {
        while (isRunning){
            System.out.println(recive());
        }
    }
}
